<template>
	<view>
		<block class="good-list">
			<view  @click='gotoDetail(item)' class="good-item" v-for="(item,index) in goodsList" :key="index">
				<my-good :goods='item'></my-good>					
			</view>
		</block>
	</view>
</template>

<script>
	export default {
		onLoad(option) {
			// this.queryObj = option;
			console.log(option)
			this.queryObj.query = option.query||''
			this.queryObj.cid = option.cid || ''
			this.getGoodLists();
		},
		data() {
			return {
				isLoading:false,
				goodsList:[],
				queryObj:{
					
					query:'',
					cid:'',
					pagenum:1,
					pageSize:10
				}
				
			};
		},
		methods:{
			gotoDetail(item) {
				uni.navigateTo({
					url:'../goods_detail/goods_detail?goods_id='+item.goods_id
				})
			},
			
			onPullDownRefresh(){
				this.queryObj.pagenum = 1;
				this.goodsList = [];
				this.getGoodLists();
			},
			onReachBottom(){
				if(this.queryObj.pagenum * this.queryObj.pageSize >= this.goodsList.length) {
					// uni.$showMsg('数据记载完毕');
				}
				if(this.isLoading == true) return;
				this.queryObj.pagenum = this.queryObj.pagenum + 1;
				this.getGoodLists();
			},
			async getGoodLists(){
				this.isLoading = true;
				const {data: res} = await uni.$http.get('/api/public/v1/goods/search',this.queryObj)
				console.log(res);
				uni.stopPullDownRefresh();
				
				if(res.meta.status != 200) {
					uni.$showMsg();
					return;
				}
				this.goodsList = [...this.goodsList,...res.message.goods];
				this.isLoading = false;
				
			}
		}
	}
</script>

<style lang="scss">
	// .good-logo image {
	// 	width: 100px;
	// 	height: 100px;
	// }
	// .good-item {
	// 	display: flex;
	// 	font-size: 12px;
	// 	margin: 10px 5px;
	// 	border-bottom: 1px solid #efefef;
	// }
	// .good-des {
	// 	display: flex;
	// 	align-items: flex-start;
	// 	flex-direction:column;
	// 	justify-content: space-between;
	// 	margin-left: 10px;
	// }
	// .good-price {
	// 	color: #c00000;
	// 	font-size: 16px;
	// 	margin-bottom: 5px;
	// }
</style>
